package com.ykzb.pay.alipay.util;


import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2016/6/16.
 */
public class AlipayManager {

    public static AlipayManager alipayManager;
    public static  AlipayManager getManager()
    {
        if (alipayManager == null)
        {
            alipayManager = new AlipayManager();
        }
        return alipayManager;
    }
    public String createPay(String feeTemp,String orderCode,String payType)
    {
        ////////////////////////////////////请求参数//////////////////////////////////////

        //商户订单号，商户网站订单系统中唯一订单号，必填
        String out_trade_no = null;
        String payFee =  feeTemp;
        String total_fee = payFee;
        String show_url = "";
        String body = "";
        String subject = "";
        try {
            out_trade_no = new String(orderCode);
            //订单名称，必填
            subject = new String(out_trade_no.getBytes("ISO-8859-1"),"UTF-8");


            //付款金额，必填
            total_fee = new String(payFee.getBytes("ISO-8859-1"),"UTF-8");

            //收银台页面上，商品展示的超链接，必填
            show_url = new String(AlipayConfig.success.getBytes("ISO-8859-1"),"UTF-8");

            //商品描述，可空
            body = new String("更省，更快捷".getBytes("ISO-8859-1"),"UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        //把请求参数打包成数组
        Map<String, String> sParaTemp = new HashMap<String, String>();
        sParaTemp.put("service", AlipayConfig.service);
        sParaTemp.put("partner", AlipayConfig.partner);
        sParaTemp.put("seller_id", AlipayConfig.partner);
        sParaTemp.put("_input_charset", AlipayConfig.charset);
        sParaTemp.put("payment_type", AlipayConfig.paymentType);
        if ("1".equals(payType))
        {

            sParaTemp.put("notify_url", AlipayConfig.gasNotifyUrl);
        }
        else
        {
            sParaTemp.put("notify_url", AlipayConfig.payNotifyUrl);
        }
        sParaTemp.put("return_url",AlipayConfig.success);
        sParaTemp.put("out_trade_no", out_trade_no);
        sParaTemp.put("subject", subject);
        sParaTemp.put("total_fee", total_fee);
        sParaTemp.put("show_url", show_url);
        sParaTemp.put("body", body);
        //其他业务参数根据在线开发文档，添加参数.文档地址:https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7629140.0.0.2Z6TSk&treeId=60&articleId=103693&docType=1
        //如sParaTemp.put("参数名","参数值");


        //建立请求
        String sHtmlText = AlipaySubmit.buildRequest(sParaTemp,"get","确认");
        return sHtmlText;
    }
}
